package com.wy.projectssj.resovler;

import com.wy.projectssj.exception.MyException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: wy
 * @Date:2019/8/30 19:37
 */
public class MyExceptionResovler implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
          ModelAndView mav=new ModelAndView();
        if(e instanceof ClassCastException){
               mav.addObject("erroeMsg","类型转换异常");
          }else if(e instanceof MyException){
               mav.addObject("errorMsg","空指针异常");
        }
          return null;
    }
}
